`include "chunjun_define.sv" 
`include "chunjun_lib_define.sv" 
 
//==============================================================
// Date        : 2024-10-16
// Description : 
//==============================================================

module wing_cbb_plru_encode #(
    parameter WAY_N  = 4
) (
    input  logic[WAY_N-1:0] way_info_i,
    input  logic[WAY_N-2:0] code_i,
    output logic[WAY_N-2:0] code_o
);

if (WAY_N == 4) begin : g_way4
 
  always_comb begin: u_plru_encode
 
    code_o = '0;
    if (way_info_i[0]) begin: u_touch_way_0
      code_o = {code_i[WAY_N-2], 2'b11};
    end else if (way_info_i[1]) begin: u_touch_way_1
      code_o = {code_i[WAY_N-2], 2'b01};
    end else if (way_info_i[2]) begin: u_touch_way_2
      code_o = {1'b1, code_i[WAY_N-3], 1'b0};
    end else if (way_info_i[3]) begin: u_touch_way_3
      code_o = {1'b0, code_i[WAY_N-3], 1'b0};
    end

  end
 
end else begin : g_way

/*
logic [WAY_N-2:0] code_reverse;
 
for (genvar i=0; i<$clog2(WAY_N); i++) begin: level
 
    localparam X = (i==0) ? 0 : ((1<<i)-1);

    for (genvar j=0; j<(2**i); j++) begin: node
        assign code_reverse[X+j] = (|way_info_i[((WAY_N/(2**i)))*j +: (WAY_N/(2**(i+1)))]) ^ code_i[X+j];
        assign code_o[X+j] = code_i[X+j] ^ code_reverse[X+j];    
    end

end
*/
 
end 
 
endmodule

`include "chunjun_undefine.sv" 
